package com.briup.cms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.cms.domain.Comment;
import com.briup.cms.domain.param.CommentQueryParam;
import com.briup.cms.service.ICommentService;
import com.briup.cms.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-03-09
 */
@Api("评论模块")
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    ICommentService commentService;

    @ApiOperation("添加一级评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "comment",value = "一级评论内容")
    })
    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment){
        commentService.addComment(comment);
        return Result.success();
    }

    @ApiOperation("删除一级评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "删除一级评论id")
    })
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        commentService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("根据文章id查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId",value = "文章id")
    })
    @GetMapping("/queryByArticleId")
    public Result queryByArticleId(Long articleId){
        List<Comment> comments =
                commentService.queryByArticleId(articleId);
        return Result.success(comments);
    }

    @ApiOperation("查询一级评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param",value = "查询条件")
    })
    @PostMapping("/query")
    public Result query(CommentQueryParam param){
        IPage<Comment> query = commentService.query(param);
        return Result.success(query);
    }
}

